package com.zhongyi.http.service;

import java.io.IOException;
import java.io.InputStream;

import com.zhongyi.entity.Contact;
import com.zhongyi.entity.SysLog;
import com.zhongyi.util.HttpUtil;
import com.zhongyi.util.StringUtil;

public class QuartzService {
	
	private MailService mailService;
	
	
	public void setMailService(MailService mailService) {
		this.mailService = mailService;
	}



	/**
	 * 定时器发送邮件
	 */
	public void quartzSendMail(){
		boolean status = false;
		SysLog sysLog = null;
//		List<Contact> contactList = mailService.queryMailList(Constant.EMAIL_PAGER_SQL,new Integer[]{0,50});
//		for(Contact con : contactList){
//			status = mailService.sendHtmlMail(con,  "/manufacture Refractory Materials and Castings/ZhongYi Foundry Co., Ltd", "Your email client does not support HTML messages.Visit www.zhongyifoundry.com for details please.", content, null);
//			
//			sysLog = new SysLog();
//			sysLog.setId(UUIDGenerator.create());
//			sysLog.setContact_id(con.getId());
//			sysLog.setContact_info(con.getContact_info());
//			sysLog.setInfo_type(con.getInfo_type());
//			sysLog.setInfo_body(content);
//			sysLog.setContact_time(new Timestamp(System.currentTimeMillis()));
//			sysLog.setStatus((status==true)?"1":"0");
//			//更新邮件状态为 "已发送"
//			if(status){
//				mailService.updateMailStatus(Constant.CONTACT_STAUTS_UPDATE_SQL, con, "1");
//			}
//			mailService.insertToSysLog(Constant.SYSLOG_INSERT_SQL, sysLog);
//		}
		
		Contact con = new Contact();
		con.setContact_info("sf314948016@126.com");
		InputStream ins = HttpUtil.getServletContext().getResourceAsStream("/template/mailTemplate.html");
		String htmlContent = StringUtil.readHtmlToString(ins);
		try {
			ins.close();
		} catch (IOException e) {
			e.printStackTrace();
		}finally{
			ins = null;
		}
		mailService.sendHtmlMail(con, "/manufacture Refractory Materials and Castings/ZhongYi Foundry Co., Ltd", "Your email client does not support HTML messages.Visit www.zhongyifoundry.com for details please.", htmlContent, null);
	}
}
